
#include "stdafx.h"
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include <iostream>
#include <windows.h>
#include<locale.h>
#include<malloc.h>
#include "stdafx.h"
#include "stdlib.h"
#include "time.h"

void merge(int *mas,int a,int c)
{
	int *rez=(int*)malloc(sizeof(int)*(c+1));
	if(a<c)
	{
		int x=(a+c)/2;
		merge(mas,a,x); merge(mas,x+1,c);
		int n1=a,n2=x+1;
		for (int i=a;i<=c;i++)
		{
			
			if ((n1<x+1)&&((n2>c)||mas[n1]<mas[n2]))
			{
				rez[i]=mas[n1];n1++;
			}
			else
			{
				rez[i]=mas[n2];
				n2++;
			}
		}
		for (int i=a;i<=c;i++)
		{
			mas[i]=rez[i];
		}
	}
	free(rez);
};
int main(int argc, char* args[])
{
	srand(time(NULL));
	int a=0,c=5;
	int mas[6];
	for (int i=0;i<=c;i++)
	{
		mas[i]=0+rand()%10;
		printf("%d ",mas[i]);
	}
	merge(mas,a,c);
	printf("\n");

	for (int i=0;i<=c;i++)
	{
		printf("%d ",mas[i]);
	}
	//int* mas=(int*)malloc(sizeof(6*int));

return 0;	
}